let yellow = Symbol("Yellow");
let yellow1 = Symbol.for("Yellow");
console.log(yellow === yellow1);      // false
 
let yellow2 = Symbol.for("Yellow");
console.log(yellow1 === yellow2);     // true

let handler = {
    construct: function (target, args, newTarget) {
        console.log('handle construct')
        return Reflect.construct(target, args, newTarget)  
    }
}
class Exam { 
    constructor (name) {  
        this.name = name
        this.age = 99
    }
}
let ExamProxy = new Proxy(Exam, handler)
let proxyObj = new ExamProxy('Tom')
console.log(proxyObj)

function sub(a, b){
    return a - b;
}
let handler1 = {
    apply: function(target, ctx, args){
        console.log('handle apply');
        console.log(target, ctx, args)
        // return Reflect.apply(...arguments);
        return 99
    }
}
let proxy = new Proxy(sub, handler1)
console.log(proxy(2, 1))


let handler2 = {
    defineProperty: function(target, propKey, propDesc){
        console.log("handle defineProperty");
        return false;
    }
}
let target1 = {}
let proxy1 = new Proxy(target1, handler2)
proxy1.name = "Jerry"
console.log(target1)
console.log(proxy1.name)

console.log(Object.prototype, Array.prototype);


// 定义 Map 集合
const mapedObservers = new Map();
// 把观察者函数都放入 Set 集合中
const observe = (key,fn) => {
    mapedObservers.has(key)?mapedObservers.get(key).push(fn):mapedObservers.set(key,[fn]);
}
// observable 返回原始对象的代理，拦截赋值操作
const observable = obj => new Proxy(obj, {"set":set, has:get111});
function set(target, key, value, receiver) {
  // 获取对象的赋值操作
  const result = Reflect.set(target, key, value, receiver);
  // 执行所有观察者
  if(mapedObservers.has(key)){
        mapedObservers.get(key).forEach(observer => observer());
  }
  // 执行赋值操作
  return result;
}
function get111(target, key,  receiver) {
    const ret = Reflect.get(target, key, receiver);
    console.log("111-< ", ret);
    if(mapedObservers.has(key)){
        mapedObservers.get(key).forEach(observer => observer());
    }
    return ret;
}
//被观察的 对象
const person = observable({
    name: '张三',
    age: 20
});
function print() {
    console.log(`我是1号观察者：${person.name}, ${person.age}`)
}
function print2() {
    console.log(`我是2号观察者：${person.name}, ${person.age}`)
}
function print3() {
    console.log(`我是3号观察者：${person.name}, ${person.age}`)
}
//添加观察者
observe('name',print);
observe('age', print2);
console.log("#######");
person.name = '李四';
console.log("#######0000");
observe('name', print3);
person.name = 'GGG';
console.log("#######*****");

'age' in person
// var name = "黄";
// var visitorNumber = 99;
// console.log(i18n`Hello ${name}, you are visitor number ${visitorNumber}.`);

// Number.MIN_VALUE
const items = ["zero", "one", "two"];
const it = items[Symbol.iterator]();
console.log(it.next());
console.log(it.next());
console.log(Symbol.iterator, it)
for( let item of items) {//迭代遍历
    console.log(item);
}

@testablea
class Examplea {}
function testablea(target) {
    target.isTestable = true;
}
Example.isTestable; // true

// function testable(isTestable) {
//     return function(target) {
//         target.isTestable=isTestable;
//     }
// }
// @testable(true)
// class Example {}
// Example.isTestable; // true